package com.csd.action.team;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.csd.helper.ActionResult;
import com.csd.helper.Tool;
import com.csd.pojo.Student;
import com.csd.pojo.Team;
import com.csd.serviceImpl.ProjectTypeService;
import com.csd.serviceImpl.StudentService;
import com.csd.serviceImpl.TeamService;


/**
 * 
 * Action：删除一个成员
 * @author csd
 * @version 1.0
 * 
 * <br> 修订时间：2009-12-17
 * <br> 修改原因：创建文件
 * <br> 修改人：刘世彬
 * 
 * <br> 
 * 
 */
public class MemberDeleteAction {
	/** 成员ID */
	private String memberID;
    private StudentService service;
    //private String projectTypeID;
    
    /*取自teamShow.action*/
	private Team team ;
	private List<Student> members;
	private Integer  projectTypeID;
	private Integer teamID;
	//private TeamService service;
	private Student member;//new add
	private ProjectTypeService projectTypeService;
	private StudentService studentService;
	private TeamService teamService;
	
//	public String getProjectTypeID() {
//		return projectTypeID;
//	}
//	public void setProjectTypeID(String projectTypeID) {
//		this.projectTypeID = projectTypeID;
//	}
	
	public Integer getProjectTypeID() {
		return projectTypeID;
	}
	public void setProjectTypeID(Integer projectTypeID) {
		this.projectTypeID = projectTypeID;
	}
	public Student getMember() {
		return member;
	}
	public void setMember(Student member) {
		this.member = member;
	}
	public ProjectTypeService getProjectTypeService() {
		return projectTypeService;
	}
	public void setProjectTypeService(ProjectTypeService projectTypeService) {
		this.projectTypeService = projectTypeService;
	}
	public List<Student> getMembers() {
		return members;
	}
	public void setMembers(List<Student> members) {
		this.members = members;
	}
	public TeamService getTeamService() {
		return teamService;
	}
	public void setTeamService(TeamService teamService) {
		this.teamService = teamService;
	}
	public Team getTeam() {
		return team;
	}
	public void setTeam(Team team) {
		this.team = team;
	}
	
	public StudentService getService() {
		return service;
	}
	public void setService(StudentService service) {
		this.service = service;
	}
	public String getMemberID() {
		return memberID;
	}
	public void setMemberID(String memberID) {
		this.memberID = memberID;
	}
	
	
	
	public String execute() {
		String result = ActionResult.fail;

		int ID = Integer.parseInt(this.memberID);
		if (service.deleteMember(ID)) {
			result = ActionResult.success;
		}
		
	/*以下部分是从teamShow.action拷贝过来，主要是为了解决跳转问题
               方法不太好，以后有时间要改进跳转结构*/
    this.team = teamService.getTeam();
	HttpSession session = ServletActionContext.getRequest().getSession();
	// 存储团队是否已经申请项目的状态
	boolean flag = false;
		
	if(this.team != null)
	{
		this.members = Tool.setToList(this.team.getMembers());
		this.teamID = this.team.getId();
		flag = teamService.hasProjectOrNot(this.team.getId());
		result = ActionResult.success;
	}	
	// 判断跳转链接是否存在projectTypeID属性
	try 
	{
		int type = this.projectTypeID;
		if (type > 0)
			flag = true;
	} catch (Exception e) {
		e.printStackTrace();
	}
	session.setAttribute("hasProjectOrNot", flag);	
		
		return result;
	}
}
